package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 衷岚
 * @version 1.0
 */
@Mapper
public interface ShoppingCartMapper {


//    /**
//     * 根据菜品查找
//     * @param dishId
//     * @param userId
//     * @param dishFlavor
//     * @return
//     */
//    @Select("select * from shopping_cart where dish_id=#{dishId} and user_id=#{userId}")
//    ShoppingCart findByDishId(@Param("dishId") Long dishId, @Param("userId") Long userId, @Param("dishFlavor") String dishFlavor);
//
//
//    /**
//     * 根据套餐查找
//     * @param setmealId
//     * @param userId
//     * @return
//     */
//    @Select("select * from shopping_cart where setmeal_id=#{setmealId} and user_id=#{userId}")
//    ShoppingCart findBySetmealId(@Param("setmealId") Long setmealId, @Param("userId") Long userId);
//

    /**
     * 加购
     * @param cart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
            "values(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime}) ")
    void add(ShoppingCart cart);


    /**
     * 根据id更新
     * @param shoppingCart
     */

    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void update(ShoppingCart shoppingCart);

    /**
     * 查询所有
     * @return
     */
    List<ShoppingCart> list(ShoppingCart cart);

    /**
     * 清空购物车
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void deleteAll(Long userId);


    /**
     * 删除购物车中一个商品
     * @param cart
     */
    @Delete("delete from shopping_cart where id=#{id}")
    void delete(ShoppingCart cart);

    /**
     * 再来一单
     * 批量加购
     * @param cartList
     */
    void insertBatch(List<ShoppingCart> cartList);
}
